// api防抖节流

<template>
  <div>
    <button @click="getList">刷新页面</button>
  </div>
</template>

<script>

import { fetchList } from '@/api/templates'
import { debounce } from '@/utils/public'

export default {
  name: 'UserDetail',
  data() {
    return {
      
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  methods: {
    // 引入公共方法js
    // 在buttom得点击事件触发方法，传入间隔时间就可以实现
    getList: debounce(function() {
      fetchList().then((response) => {
        if (response.code === 200) {
          const {code, data} = response.result
          // 业务逻辑
          if(code === 200) {
            this.list = data
            this.$message.success('成功')
          }
        }
      })
    }, 1000)
  }
}
</script>

<style lang="scss" scoped>
@import '~@/styles/mixin.scss';
</style>
